{% extends "base.html" %}
{% load staticfiles %}
{% block title %}课程机构列表 - 我的英雄学院{% endblock %}
{% block custom_bread %}
    <section>
        <div class="wp">
            <ul  class="crumbs">
                <li><a href="{% url 'index' %}">首页</a>></li>
                <li>课程机构</li>
            </ul>
        </div>
    </section>
{% endblock  %}
{% block content %}
<section>
	<div class="wp butler_list_box list">
	<div class='left'>
		<div class="listoptions">
			<ul>
				<li>
					<h2>机构类别</h2>
					<div class="cont">
                        <a href="?city={{city_id}}"><span class="{% ifequal category '' %}active2{% endifequal %}">全部</span></a>

                            <a href="?ct=pxjg&city={{city_id}}"><span class="{% ifequal 'pxjg' category %}active2{% endifequal %}">培训机构</span></a>
                        
                            <a href="?ct=yx&city={{city_id}}"><span class="{% ifequal 'yx' category %}active2{% endifequal %}">英雄高校</span></a>

                            <a href="?ct=dx&city={{city_id}}"><span class="{% ifequal 'dx' category %}active2{% endifequal %}">大学个人</span></a>

					</div>
				</li>
				<li>
					<h2>所在地区</h2>
					<div class="more">更多</div>
					<div class="cont">
                        <a href="?ct={{category}}"><span class="{% ifequal city_id '' %}active2{% endifequal %}">全部</span></a>
                            {% for city in all_city %}
                                <a href="?city={{city.id}}&ct={{category}}"><span class="{% ifequal city_id city.id|stringformat:'i' %}active2{% endifequal %}">{{ city.name }}</span></a>
                            {% endfor %}
                            
					</div>
				</li>
			</ul>
		</div>
		<div class="all">共<span class="key">{{ org_nums }}</span>家</div>
		<div class="butler_list company list">
		<div class="layout">
			<div class="head">
				<ul class="tab_header">
					<li class="{% if sort == '' %}active{% endif %}"><a href="?city={{city.id}}&ct={{category}}">全部</a> </li>
					<li class="{% if sort == 'students' %}active{% endif %}"><a href="?sort=students&city={{city_id}}&ct={{category}}">学习人数 &#8595;</a></li>
					<li class="{% if sort == 'courses' %}active{% endif %}"><a href="?sort=courses&city={{city_id}}&ct={{category}}">课程数 &#8595;</a></li>
				</ul>
			</div>
            {% for course_org in all_org.object_list %}  
            <!--因为all_org已经变成了orgs的渲染，而在view中orgs = p.page(page)，是Prue-pagination的实例，里面它把原先数据库里的数据打包成list了，所以要加上".object_list"-->
                <dl class="des difdes">
                    <dt>
                        <a href="{% url 'org:org_home' course_org.id %}">
                            <img width="200" height="120" class="scrollLoading" data-url="{{ MEDIA_URL }}{{ course_org.image }}"/>
                        </a>
                    </dt>
                    <dd>
                        <div class="clearfix">
                             <a href="{% url 'org:org_home' course_org.id %}">
                                 <h1>{{ course_org.name }}</h1>
                                 <div class="pic fl">

                                         <img src="{% static 'images/authentication.png' %}"/>

                                         <img src="{% static 'images/gold.png' %}"/>

                                 </div>
                             </a>
                        </div>
                        <ul class="cont">
                            <li class="first"><p class="pic9">课程数：<span>{{course_org.course_nums}}</span></p><p class="c7">学习人数：<span>{{course_org.students}}</span></p></li>
                            <li class="c8" style="padding-left:18px;">{{course_org.address}}</li>
                            <li class="pic10" style="padding-left:18px;">经典课程：
                                {% for row in all_org.object_list.get_all_course %}
                                    <a href="{% url 'course:course_detail' row.id %}">{{row.name}}</a>
                                {% endfor %}
                            </li>
                        </ul>
                    </dd>
                    <div class="buy start_groupbuy jsShowPerfect2" data-id="22"><br/>联系<br/>服务</div>
                </dl>
            {% endfor %}
            
		</div>
		 <div class="pageturn">
            <ul class="pagelist">
                {% if all_org.has_previous %}
                    <li class="long"><a href="??{{ all_org.previous_page_number.querystring }}">上一页</a></li>
                {% endif %}
                {% for page in all_org.pages %}
                    {% if page %}
                        {% ifequal page all_org.number %}
                        <li class="active"><a href="?{{ page.querystring }}">{{ page }}</a></li>
                        {% else %}
                        <li><a href="?{{ page.querystring }}" class="page">{{ page }}</a></li>
                        {% endifequal %}
                    {% else %}
                        <li class="none"><a href="">...</a></li>
                    {% endif %}
                {% endfor %}
                {% if all_org.has_next %}
                    <li class="long"><a href="?{{ all_org.next_page_number.querystring }}">下一页</a></li>
                {% endif %}
                    <!--
                             <li class="active"><a href="?page=1">1</a></li>
                             <li><a href="?page=2" class="page">2</a></li>
                             <li><a href="?page=3" class="page">3</a></li>
                             <li class="long"><a href="?page=2">下一页</a></li>
                -->

            </ul>
        </div>
		</div>
	</div>
	<div class="right companyright">
			<div class="head">我要学习</div>
			<form class="rightform" id="jsStayForm">
				<div>
                    <img src="{% static 'images/rightform1.png' %}"/>
                    <input type="text" name="name" id="companyName" placeholder="名字" maxlength="25" />
                </div>
				<div>
                    <img src="{% static 'images/rightform2.png' %}"/>
                    <input type="text" name="mobile" id="companyMobile" placeholder="联系电话"/>
                </div>
				<div>
                    <img src="{% static 'images/rightform3.png' %}"/>
                    <input type="text" name="course_name" id="companyAddress" placeholder="课程名" maxlength="50" />
                </div>
                <p class="error company-tips" id="jsCompanyTips"></p>
				<input class="btn" type="text" id="jsStayBtn" value="立即咨询 >" />
            <input type='hidden' name='csrfmiddlewaretoken' value='5I2SlleZJOMUX9QbwYLUIAOshdrdpRcy' />
            </form>
		</div>

		<div class="right companyrank layout">
			<div class="head">授课机构排名</div>
            
            {% for row in hot_orgs %}
               <dl class="des">
                   <!--在%for%循环内部,可以访问一个名为forloop的模板变量。这个变量有若干属性,通过它们可以获知循环进程的一些信息。-->
                    <dt class="num fl">{{forloop.counter}}</dt>
                    <dd>
                        <a href="{% url 'org:org_home' row.id %}"><h1>{{row.name}}</h1></a>
                        <p>{{row.address}}</p>
                    </dd>
                </dl>
            {% endfor %}
                
            
  

		</div>
        </div>
</section>
{% endblock  %}

{% block custom_js %}
<script>
    $(function(){
        $('#jsStayBtn').on('click', function(){
            $.ajax({
                cache: false,
                type: "POST",
                url:"{% url 'org:add_ask' %}",
                data:$('#jsStayForm').serialize(),
                async: true,
                success: function(data) {
                    console.log(data)
                    if(data.status == 'success'){
                        $('#jsStayForm')[0].reset();
                        alert("提交成功")
                    }else if(data.status == 'fail'){
                        $('#jsCompanyTips').html(data.msg)
                    }
                },
            });
        });
    })

</script>
{% endblock  %}